package com.xzl.manger.server;

import com.xzl.manger.dao.IGoodsDao;
import com.xzl.manger.model.Goods;
import com.xzl.manger.model.GoodsType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GoodsServer {
    @Autowired
    private IGoodsDao goodsDao;
    public List<Goods> selectGoods(Goods good){
        List<Goods> list = goodsDao.selectGoods(good);
        return list;
    }
    public List<Goods> selectGoodsOnSale(Goods good){
        List<Goods> list = goodsDao.selectGoodsOnSale(good);
        return list;
    }
    public List<Goods> selectGoodsNoSale(Goods good){
        List<Goods> list = goodsDao.selectGoodsNoSale(good);
        return list;
    }
    public List<GoodsType> selectTypes(){
        return goodsDao.selectTypes();
    }

    public Integer insertGoods(Goods g){
        if(g!=null) return goodsDao.insertGoods(g);
        else return 0;
    }
    public Integer updateGoods(Goods g){
        if(g!=null) return goodsDao.updateGoods(g);
        else return 0;
    }
    public Integer downGoods(String ids){
        if(ids != null && !ids.isEmpty()){
            String[] id = ids.split(",");
            return goodsDao.downGoods(id);
        }
        return 0;
    }
    public Integer upGoods(String ids){
        if(ids != null && !ids.isEmpty()){
            String[] id = ids.split(",");
            return goodsDao.upGoods(id);
        }
        return 0;
    }
    public Integer insertTypes(GoodsType gt){
        if(gt==null||gt.getName()==null||gt.getName()=="") return 0;
        return goodsDao.insertTypes(gt);
    }
}
